package com.wlgc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wlgc.dao.UserDao;
import com.wlgc.entity.Assigment.Student_Assigment;
import com.wlgc.entity.RestBean;
import com.wlgc.entity.User;
import com.wlgc.mapper.AssignmentMapper;
import com.wlgc.service.AssignmentService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class AssignmentServiceImpl implements AssignmentService {

    @Resource
    AssignmentMapper assignmentMapper;
    @Resource
    UserDao dao;


    @Override
    public RestBean selectAssignment(int a) {
        List<Student_Assigment> list;
        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username", username).select("id");
        User user = dao.selectOne(wrapper);


        if (a == 0) {
            return new RestBean<>(200, "", assignmentMapper.get_All_Assigment(user.getId().intValue()));
        } else if (a == 1) {
            return new RestBean<>(200, "", "");
        } else {
            return new RestBean<>(200, "", "");
        }


    }

    public RestBean getClassAssigmentCondition(int refer, int cno) {

        if (refer == 0) {
            return new RestBean<>(200, "", assignmentMapper.getClassStudent_UF(cno));
        } else if (refer == 1) {
            return new RestBean<>(200, "", "");
        } else {
            return new RestBean<>(200, "", "");
        }


    }
    public RestBean getClass_Course_Condition(int refer,int cno,int cid)
    {
        if (refer == 0) {
            return new RestBean<>(200, "",assignmentMapper.getClass_Course_Student_UF(cno, cid));
        } else if (refer == 1) {
            return new RestBean<>(200, "", assignmentMapper.getClass_Course_Student_F(cno,cid));
        } else {
            List<Student_Assigment> list=assignmentMapper.getClass_Course_Student_F(cno,cid);
         assignmentMapper.getClass_Course_Student_UF(cno,cid).forEach(student_assigment -> {
             list.add(student_assigment);
         });

            return new RestBean<>(200, "",list );
        }
    }

    //将中文转化为参数
    @Override
    public String translate(String refer) {
        if(refer.equals("全部"))
        {
            refer="10";
        } else if (refer.equals("已完成")) {
            refer="1";
        } else if (refer.equals("未完成")) {
            refer="0";
        }
        return refer;
    }
}
